package com.xiaozhengkeji.springboot.speed.utils;

import org.springframework.util.DigestUtils;

import java.io.IOException;

/**
 * 加密解密工具集
 */
public class EncryptUtil {
    /**
     * Baser64加密
     *
     * @param content 需要加密的字符串
     */
    public static String Base64加密(String content) {
        return new sun.misc.BASE64Encoder().encode(content.getBytes());
    }

    /**
     * Baser64解密
     *
     * @param source 需要解密字符串
     */
    public static String Base64解密(String source) {
        try {
            sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
            return new String(decoder.decodeBuffer(source));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static String MD5加密(String set) {
        return DigestUtils.md5DigestAsHex(set.getBytes());
    }
}
